 <template>
 <div>
          <div class="crumbs">
            <el-breadcrumb separator="/">
                <h3 style="color #DDDDDD">当前位置:冲突检测</h3>
            </el-breadcrumb>
        </div>
<el-button type="text" @click="open">检验</el-button>
<el-button type="text" @click="add">导入</el-button>
<el-dialog title="新增" v-model="dialogFormVisible">
	<div >
	<upload-excel-component  :on-success="handleSuccess" :before-upload="beforeUpload" />
	</div>
	<div slot="footer" class="dialog-footer" style="display: flex;justify-content: flex-end;">
	    <el-button @click="dialogFormVisible = false">关闭</el-button>
	    <el-button type="primary" @click="submitUpload">确认导入</el-button>
	  </div>
</el-dialog>

    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column  
        prop="id"
        label="序号"
        width="250">
      </el-table-column>
      <el-table-column
        prop="date"
        label="日期"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="amorpm"
        label="上午/下午"
        width="250">
      </el-table-column>
      <el-table-column
        prop="time"
        label="考试时间"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="major"
        label="专业"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="year"
        label="年级"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="classname"
        label="班级名称"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="course"
        label="课程名称"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="classroomObj.kszw"
        label="人数"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="classroomObj.xq"
        label="校区"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="classroomObj.classroomname"
        label="教室名称"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="teacherObj.mainteacher"
        label="主监考教师"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="teacherObj.viceteacher"
        label="副监考教师"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="teacherObj.iscancelinvigilate"
        label="是否免监考"
        width="250"
        >
      </el-table-column>
      <el-table-column
        prop="teacherObj.xunkaoteacher"
        label="巡考教师"
        width="250"
        >
      </el-table-column>
    </el-table>
    <el-pagination
    background
  layout="prev, pager, next"
  :page-size="currentPage.page"
  :total="currentPage.total"
  :page-count="currentPage.count"
  :current-page="currentPage.current"
  @current-change="page">
  
  >
</el-pagination>
 </div>
</template>
<script>
  import { saveCheckInfo,findExamInfo,cd} from '../api/index.js'
  import UploadExcelComponent from '../components/UploadExcel/index.vue'
    export default {
        created(){
           this.getdata(1);
        },
		components:{
			UploadExcelComponent
		},
        data() {
            return {
                total: null,
                tableData: null,
				sb:null,
                dialogFormVisible:false,
				filelist:[],
				file:[],
                currentPage:{
                  page:1,
                  total:20,
                  count:50,
                  current:0 ,
                  limit:10
                }
            }
        },
		methods: {
			
			submitUpload () {
			      saveCheckInfo({'hander':this.tableHeader,'body':this.sb}).then(res=>{
					  console.log("返回数据====>"+res)
					  this.$nextTick(()=>{
						  this.getdata(this.currentPage.page);
					  })
				  })
			    },
			  beforeUpload(file) {
				  console.log(file);
				  this.file=file
			      const isLt1M = file.size / 1024 / 1024 < 1
			      if (isLt1M) {
			        return true
			      }
			      this.$message({
			        message: 'Please do not upload files larger than 1m in size.',
			        type: 'warning'
			      })
				  console.log(file);
				  this.file=file
			      return false
			    },
			    handleSuccess({ results, header }) {
			      this.sb = results
			      this.tableHeader = header
				  
			  },
			//文件列表增加时
			fileChange(file, fileList){
				console.log(this.filelist)
			let fileType=file.name.substring(file.name.lastIndexOf('.')+1);
			        if(fileType !=='xlsx' &&fileType!=='xls'){
			          this.$message.error("文档格式不正确，请上传excel文件");
			          return false;
			        }
			        if(file.size / 1024 /1024 >100){
			          this.$message.error("文档大小不能超过100M");
			          return false;
			        }
			        this.file=file.raw;
			},
			
			
			/* //文件列表减少时
			 handleRemove(file, fileList) {
			        console.log(file, fileList);
			},
			handlePreview(file) {
			        console.log(file);
			},
			handleExceed(files, fileList) {
			 this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
			},
			beforeRemove(file, fileList) {
			  return this.$confirm(`确定移除 ${ file.name }？`);
			}, */
			
			
		    open(){

		         cd({}).then(res=>{
					 if(res.code==1){
							this.$message({
									  message: res.msg,
									  type: 'success'
									});
					 }else{
						 
						 // var msglist={};
						 // var msgObj=[]
						 // var pretemp={};
						 // var tempdata=deepClone(res.data)
						 // for(var x=0;x<res.data.length;x++){
							//  var temp1=res.data[x];
							//  var id=temp1.id;
							//  var msg='序号为'+id
							// 	for(var y=0;y<tempdata.length;y++){
							// 		var temp2=tempdata[y]
							// 		if(temp2.date_time==temp1.date_time&&temp2.id!=temp1.id){
							// 			msg+=","+temp2.id
							// 			 tempdata.splice(y,1); 
							// 			 if(x){
							// 				 res.data.splice(y,1);
							// 			 }
							// 			 y--;
							// 			 x--;
										
							// 		}
									
							// 	}
								
							// 	msg+="的记录，考试时间与考试教室有冲突！"
							// 	msgObj[x]=msg
						 // }
						 // console.log(msgObj)
						 
						  this.$notify({
						           title: '冲突检测',
						           message: '记录中有多条记录的考试时间与考试教室有冲突，请详细核对！',
								   type: 'warning',
						           duration: 0
						         });
					 }
				 });
		    },
		    add(){
			  this.dialogFormVisible=true;
		    },
		    getdata(obj){
		    				this.currentPage.page=obj
		    				findExamInfo(this.currentPage).then(Object=>{
		    				  this.tableData=Object.records[0];
		    					console.log(Object);
		    					this.currentPage.total=Object.rowCount;
		    					this.currentPage.page=Object.pageCurrent;
		    				})
		    }, 
		    handleClick(row) {
		        console.log(row);
		    },
		    page(currentPage){
		         this.getdata(currentPage);  
		    }
		}
    }
	function deepClone(target) {
	  let result
	  if (typeof target === 'object') { // 如果当前需要深拷贝的是一个对象
	    if (Array.isArray(target)) { // 如果是一个数组
	      result = [] // 将result赋值为一个数组，并且执行遍历
	      for (let i in target) {
	        result.push(deepClone(target[i])) // 递归克隆数组中的每一项
	      }
	    } else if (target === null) {
	      result = null // 判断如果当前的值是null，直接赋值为null
	    } else if (target.constructor === RegExp) {
	      result = target // 判断如果当前的值是一个RegExp对象，直接赋值
	    } else {
	      result = {} // 否则是普通对象，直接for in循环，递归赋值对象的所有值
	      for (let i in target) {
	        result[i] = deepClone(target[i])
	      }
	    }
	  } else {
	    result = target // 如果不是对象，就是基本数据类型，直接赋值
	  }
	  return result // 返回最终结果
	}
</script>